package com.singzi.javaSenior.threads.basic;

public class CommunicationTest {
    public static void main(String[] args) {
        Number number = new Number();
        Thread t1 = new Thread(number);
        Thread t2 = new Thread(number);
        t1.start();
        t2.start();
    }
}
class Number implements Runnable{
    private int number = 1;
    Object object = new Object();
    @Override
    public void run() {
        while (true){
            synchronized (this) {


                notify();
                if(number <= 100){
                    System.out.println(Thread.currentThread().getName() + " :" + number);
                    number++;
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else break;
            }
        }
    }
}